﻿/*
 * RegExpress
 * 
 * Copyright (c) 2010, Daniel McGaughran
 * 
 * Licensed under the Apache Licence, Version 2.0 (the "Licence");
 * you may not use this file except in compliance with the Licence.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 * 
 */

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using RegExpressModel;
using RegExpressViewModel.Commands;


namespace RegExpressViewModel
{
	public partial class MainWindowViewModel : ViewModelBase
	{
		private SlideViewModel _currentSlide;

		#region Physical Window Properties

		[DefaultValue(Visibility.Hidden)]
		public Visibility Visibility { get; set; }


		public double MaxWidth { get; set; }
		public double MaxHeight { get; set; }


		public double MinWidth 
		{
			get { return (double)WindowSettings.MinWidth; }
		}

	
		public double MinHeight
		{
			get { return (double)WindowSettings.MinHeight; }
		}


		public double CurrentWidth
		{
			get { return (double)_winSettings.Width; }
			set 
			{
				_winSettings.Width = (int)Math.Min(Math.Max(MinWidth, value), MaxWidth);
				OnPropertyChanged("CurrentWidth");
			}
		}


		public double CurrentHeight
		{
			get { return (double)_winSettings.Height; }
			set
			{
				_winSettings.Height = (int)Math.Min(Math.Max(MinHeight, value), MaxHeight);
				OnPropertyChanged("CurrentHeight");
			}
		}


		public WindowState WindowState
		{
			get { return (_winSettings.IsMaximised)? WindowState.Maximized : WindowState.Normal; }
			set
			{
				_winSettings.IsMaximised = (value == WindowState.Maximized);
				OnPropertyChanged("WindowState");
			}
		}

		#endregion


		public static MainWindowViewModel Instance
		{ get; private set; }



		public SettingsViewModel SettingsViewModel
		{
			get { return _settings; }
		}


        public Uri CurrentSlideUri
        {
            get
            {
				if (_model != null && _model.CurrentSlide != null)
				{
					string uri = String.Format(_pageUriTemplate, _model.CurrentSlide.TemplateName);
					return new Uri(uri, UriKind.Relative);
				}

				return null;
            }
        }


		public SlideViewModel CurrentSlide
		{
			get
			{
				return _currentSlide;
			}
			set
			{
				value.UpdateToVar(ref _currentSlide, OnPropertyChanged, "CurrentSlide");
			}
		}


		#region Commands

		public ICommand CloseCmd { get; set; }

		public ICommand FirstSlide { get; set; }
		public IVMCommand PrevSlide { get; set; }
		public IVMCommand NextSlide { get; set; }


		#endregion


	}
}
